import Vue from 'vue'
import VueRouter from 'vue-router'
import notFound from '../views/NotFound.vue'
import AuthFail from '../views/AuthFail.vue'
import Binding from '../views/Binding.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/404',
    name: '404',
    component: notFound,
    meta: {
      title: '404',
    },
  },

  {
    path: '/',
    name: 'index',
  },

  {
    path: '/auth-fail',
    name: 'auth-fail',
    component: AuthFail,
    meta: {
      title: '无权限访问',
    },
  },

  {
    path: '/binding',
    name: 'binding',
    component: Binding,
    meta: {
      title: '绑定',
    },
  },
]

const router = new VueRouter({
  base: process.env.VUE_APP_PATH,
  mode: 'history',
  routes,
})

router.beforeEach(({ meta }, from, next) => {
  if (meta.title) document.title = meta.title
  next()
})

export default router
